package com.wendy.common.core.json.jackson;

import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import org.springframework.stereotype.Component;

/**
 * @Author: ALEX WANG
 * @Date: 2020/3/17 18:56
 */
@Component
public class MyAnnotationIntrospector extends JacksonAnnotationIntrospector {
    public MyAnnotationIntrospector() {
        super();
    }

    @Override
    public Object findSerializer(Annotated a) {
        EnumSerializer ann = _findAnnotation(a, EnumSerializer.class);
        if (ann != null) {
            @SuppressWarnings("rawtypes")
            Class<? extends JsonSerializer> serClass = ann.using();
            if (serClass == MyEnumSerializer.class) {
                return new MyEnumSerializer(ann.key());
            }
        }
        DataMaskingSerializer dms = _findAnnotation(a, DataMaskingSerializer.class);
        if (dms != null) {
            DataMaskingEnum type = dms.type();
            return new MyDataMaskingSerializer(type,dms.prefixNoMaskLen(),dms.suffixNoMaskLen(),dms.mask());
        }
      /*  ToJsonObjectSerializer to = _findAnnotation(a, ToJsonObjectSerializer.class);
        if (to != null) {
            return new MyObjectToJsonSerializer();
        }*/
        return super.findSerializer(a);
    }
}
